<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>后台用户管理</title>
	<script type="text/javascript" src="js/jquery-2.1.1.js"></script>
	<link rel="stylesheet" href="css/reset.css" />
	<link rel="stylesheet" href="css/content.css" />
	<script type="text/javascript">
	

			var currpage = '${sessionScope.userpage.currentpage}';
			var total = '${sessionScope.userpage.totalpage}';
	
    $(function(){
    //alert(1);
		$("#nextpage").click(function(){
			//alert(currpage);
			//alert(total);
					if(currpage==total){
						return;
					}else{
					//alert(parseInt(currpage));
						currpage=parseInt(currpage)+1;
					}
			//alert(parseInt(currpage));
			page(currpage);
			$("#nowpage").text(currpage);
		});	
		
		$("#prepage").click(function(){
			//alert(currpage);
			//alert(total);
					if(currpage==1){
					//alert(parseInt(currpage));
						return;
					}else{
						currpage=parseInt(currpage)-1;
					
					}
			//alert(parseInt(currpage));
			page(currpage);
			$("#nowpage").text(currpage);
		});	
		
		$("#skip").click(function(){
			var pg = $("#pagecurr").val();
			page(pg);
			$("#nowpage").text(pg);
		});
		
		$("#firstpage").click(function(){
			page(1);
			$("#nowpage").text(1);
		});
		
			
	function page(pg){
		//alert(pg);
			$.ajax({
				type:'post',
				url:'${pageContext.request.contextPath }/ajax/pagequeryuserajax',
				data:{
					curr:pg,
					name:$("#searchadminname").val(),
					status:$("#searchadminstatus").val()
				},
				success:function(response,status,xhr){
							//alert(1);
					var jsonobj = eval('('+response+')');
					var lengthlist = jsonobj.userlist.length;
		    		//alert(lengthlist);
					$("#tb").empty();
							var tbobj = document.getElementById("tb");
							for(var i=0;i<lengthlist;i++){
							//alert(jsonobj.userlist[i].tegistTime);
									var optTr = document.createElement("tr");
					    		    var optObj1 = document.createElement("td");
					    		    var optObj2 = document.createElement("td");
					    		    var optObj3 = document.createElement("td");
					    		    var optObj4 = document.createElement("td");
					    		    var optObj5 = document.createElement("td");
					    		    var optObj6 = document.createElement("td");
					    		    optObj1.innerHTML=jsonobj.userlist[i].userId;
					    		    optObj2.innerHTML=jsonobj.userlist[i].userName;
					    		    optObj3.innerHTML=jsonobj.userlist[i].useremail;
					    		    optObj4.innerHTML=jsonobj.userlist[i].tegistTime;
					    		    optObj5.innerHTML=jsonobj.userlist[i].activate==1?'未激活':'已激活';
					    		    optObj6.innerHTML="<div class='table-fun'>"+
										"<a onclick='remove(optObj1);' style='cursor:pointer;'>删除</a></div>";
					    		    optTr.appendChild(optObj1);
					    		    optTr.appendChild(optObj2);
					    		    optTr.appendChild(optObj3);
					    		    optTr.appendChild(optObj4);
					    		    optTr.appendChild(optObj5);
					    		    optTr.appendChild(optObj6);
					    		    tbobj.appendChild(optTr);
							}	
			
				}
			});		
	}
	
	$("#searchusername,#searchuserstatus").keyup(function(){
			$.ajax({
					type:'post',
					url:'${pageContext.request.contextPath}/ajax/namequeryuserajax',
					data:{
						curr:1,
						name:$("#searchusername").val(),
						status:$("#searchuserstatus").val()
					},
					
				    success:function(response,status,xhr){
						var jsonobj = eval('('+response+')');
						$("#ttpage").text(jsonobj.totalpage);
						var lengthlist = jsonobj.userlist.length;
						//alert(lengthlist);
						if(lengthlist==0){
							alert("您查询的用户不存在！！！");
						}else{
							$("#tb").empty();
							var tbobj = document.getElementById("tb");
							
							for(var i=0;i<lengthlist;i++){
							//alert(jsonobj.userlist[i].tegistTime);
									var optTr = document.createElement("tr");
					    		    var optObj1 = document.createElement("td");
					    		    var optObj2 = document.createElement("td");
					    		    var optObj3 = document.createElement("td");
					    		    var optObj4 = document.createElement("td");
					    		    var optObj5 = document.createElement("td");
					    		    var optObj6 = document.createElement("td");
					    		    optObj1.innerHTML=jsonobj.userlist[i].userId;
					    		    optObj2.innerHTML=jsonobj.userlist[i].userName;
					    		    optObj3.innerHTML=jsonobj.userlist[i].useremail;
					    		    optObj4.innerHTML=jsonobj.userlist[i].tegistTime;
					    		    optObj5.innerHTML=jsonobj.userlist[i].activate==1?'未激活':'已激活';
					    		    optObj6.innerHTML="<div class='table-fun'>"+
										"<a onclick='remove(optObj1);' style='cursor:pointer;'>删除</a></div>";
					    		    optTr.appendChild(optObj1);
					    		    optTr.appendChild(optObj2);
					    		    optTr.appendChild(optObj3);
					    		    optTr.appendChild(optObj4);
					    		    optTr.appendChild(optObj5);
					    		    optTr.appendChild(optObj6);
					    		    tbobj.appendChild(optTr);
							}	
						}
						
					}	
			});
		});
	
});
			
		function remove(id){
    		if(confirm("您确定要删除编号为  ["+id+"]  的用户      (也将删除该用户所发布的所有二手商品)")){
    			$.ajax({
    				type:'post',
    				url:'${pageContext.request.contextPath}/ajax/removeuserajax',
    				data:{
    					userid:id
    				},
    				
    				success:function(response,status,xhr){
    					if(response==true){
    						alert("删除成功");
    					}
    				}
    			});
    		}	
    	}
	
	
	
			
	
	</script>
</head>
<body marginwidth="0" marginheight="0" onload="showstatus();">
	<div class="container">
		<div class="public-nav">您当前的位置：<a>管理首页</a>><a>用户管理</a></div>
		<div class="public-content">
			<div class="public-content-header">
				<h3>用户列表
				<span style="float:right;margin-right:15px;">
					<label style="color:#333">名称搜索：</label><input type="text" placeholder="名称搜索用户" id="searchusername" style="height:20px"/>&nbsp;
					<label style="color:#333">激活状态搜索：</label><input type="text" placeholder="1：未激活 2：已激活" id="searchuserstatus" style="height:20px"/>
				</span>
				</h3>
			</div>
			<div class="public-content-cont">
				<table class="public-cont-table">
					<tr>
						<th style="width:20%">编号</th>
						<th style="width:20%">名称</th>
						<th style="width:20%">邮箱</th>
						<th style="width:20%">注册时间</th>
						<th style="width:20%">激活状态</th>
						<th style="width:20%">操作</th>
					</tr>
					<tbody id="tb">
					<c:forEach items="${sessionScope.userpage.userlist}" var="user" varStatus="a">
					<tr>
						<td>${user.userId}</td>
						<td>${user.userName}</td>
						<td>${user.useremail}</td>
						<td>${user.tegistTime}</td>
						<td name="activate">${user.activate==1?"未激活":"已激活"}</td>
						<td>
							<div class="table-fun">
								<a onclick="remove('${user.userId}');" style="cursor:pointer;">删除</a>
							</div>
						</td>
					</tr>
					</c:forEach>
					</tbody>
				</table>
				<div><a style="colorground:red">注：已激活状态的用户才可登录访问二手网</a></div>
				<div class="page">
						<a id="firstpage" style="cursor:pointer;">首页</a>
						<a id="prepage" style="cursor:pointer;">上一页</a>
						<a id="nextpage" style="cursor:pointer;">下一页</a>
						第<span style="color:red;font-weight:600" id="nowpage">1</span>页
						共<span style="color:red;font-weight:600" id="ttpage">${sessionScope.userpage.totalpage}</span>页
						<input id="pagecurr" type="text" class="page-input">
						<input type="submit" class="page-btn" value="跳转" id="skip">
				</div>
			</div>
		</div>
	</div>
</body>
</html>